//MINI UI解析
mini.parse();

/**
 * 订单取消处理器类
 */
function CancelOrderHandler() {
};

CancelOrderHandler.instance = new CancelOrderHandler();
CancelOrderHandler.mgrData = new OrderMgrData();
CancelOrderHandler.cancelOrderForm = new mini.Form("cancelOrderForm");
CancelOrderHandler.hiddenForm = new mini.Form("hiddenForm");
CancelOrderHandler.hiddenForm.loadingMsg = CancelOrderHandler.mgrData.operatingMsg;

CancelOrderHandler.lolOremark = mini.get("lolOremark");
CancelOrderHandler.boiIsrefund = mini.get("boiIsrefund");
CancelOrderHandler.boiCreason = mini.get("boiCreason");
CancelOrderHandler.boiRefundremark = mini.get("boiRefundremark");
CancelOrderHandler.boiIsrefund.setData(CancelOrderHandler.mgrData.boiIsrefundData);

CancelOrderHandler.boiId = null;
CancelOrderHandler.disposeType = null;
CancelOrderHandler.boiRR = null;
CancelOrderHandler.selectNum = null;
CancelOrderHandler.isBatch = null;

/**
 * 标准方法接口定义
 * @param {} data
 */
CancelOrderHandler.passData = function(data) {
    data = mini.clone(data);
    CancelOrderHandler.isBatch = data.isBatch;
    CancelOrderHandler.boiId = data.boiId;
    
    if (data.isPaid) {
    	CancelOrderHandler.boiIsrefund.setValue(1);
		CancelOrderHandler.boiRefundremark.enable();
    }else{
    	CancelOrderHandler.boiIsrefund.setValue(0);
    	CancelOrderHandler.boiRefundremark.disable();
    }
    
    if(data.isBatch){
	    CancelOrderHandler.selectNum = data.selectNum;
    }else{
	    CancelOrderHandler.disposeType = data.disposeType;
	    CancelOrderHandler.lolOremark.setValue(data.lolOremark);
    }
}

/**
 * 是否退款单选按钮点击事件处理程序
 */
CancelOrderHandler.boiIsrefund.on("valuechanged", function(){
	if(CancelOrderHandler.boiIsrefund.getValue() == 0){
		CancelOrderHandler.boiRR = CancelOrderHandler.boiRefundremark.getValue();
		CancelOrderHandler.boiRefundremark.setValue("");
		CancelOrderHandler.boiRefundremark.disable();
	}else{
		CancelOrderHandler.boiRefundremark.setValue(CancelOrderHandler.boiRR);
		CancelOrderHandler.boiRefundremark.enable();
	}
})

/**
 * 取消订单处理程序
 * @param {} url
 */
CancelOrderHandler.executeCancel = function(url){
	CancelOrderHandler.hiddenForm.loading();
	
	$.ajax({
	        url: url,
	        type: "post",
	        dataType : 'json',
	        data: {
	    		boiId: CancelOrderHandler.boiId, 
	    		disposeType: CancelOrderHandler.disposeType,
	    		operateUType: gbOperateUType,
	    		operateUser: gbOperateUser,
	    		operateIp: gbOperateIp, 
	    		lolOremark: CancelOrderHandler.lolOremark.getValue(),
	    		boiCreason: CancelOrderHandler.boiCreason.getValue(),
	    		boiIsrefund: CancelOrderHandler.boiIsrefund.getValue(),
	    		boiRefundremark: CancelOrderHandler.boiRefundremark.getValue()
	        },
	        cache: false,
	        success: function (text) {
	        	CancelOrderHandler.closeCurrentWin("save");
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	        	MiniuiTools.miniError("系统提示", "操作失败！" + jqXHR.responseText);
	        },
			complete : function(){
				CancelOrderHandler.hiddenForm.unmask();
			}
	    });
}

/**
 * 取消订单点击事件处理程序
 */
CancelOrderHandler.cancelOrder = function(){
	//验证form表单	
    CancelOrderHandler.cancelOrderForm.validate();
    if (CancelOrderHandler.cancelOrderForm.isValid() == false) return;
    
    if(CancelOrderHandler.isBatch != null && CancelOrderHandler.isBatch){
    	mini.confirm("是否取消选中的" + CancelOrderHandler.selectNum + "条订单资源？" ,"系统提示",
			function(action, value){
				if (action == "ok") {
					CancelOrderHandler.executeCancel(CancelOrderHandler.mgrData.quXiaoOrdersUrl());
				}
		});
    }else{
    	CancelOrderHandler.executeCancel(CancelOrderHandler.mgrData.disposeOrderUrl());
    }
}

/**
 * 关闭窗口
 * @param {} action
 */
CancelOrderHandler.closeCurrentWin = function(action) {
    if (window.CloseOwnerWindow) window.CloseOwnerWindow(action);
    else window.close();
}

CancelOrderHandler.closeMiniWin = function(){
	CancelOrderHandler.closeCurrentWin("cancel");
}